<template>
  <div class="side">
    <div
      :class="isActive(item.url)"
      v-for="(item, index) in items"
      :key="index"
      @click="go(item.url)"
    >
      <component :is="item.icon" :style="{ fontSize: '24px' }" />
      <div class="side-item__text">{{ item.text }}</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import {
    CloudUploadOutlined,
    PlayCircleOutlined,
    CloudDownloadOutlined,
    CopyOutlined,
  } from '@ant-design/icons-vue';
  import { CSSProperties, computed, reactive } from 'vue';
  import { useRoute, useRouter } from 'vue-router';

  const items = reactive([
    {
      icon: CloudUploadOutlined,
      text: '上传',
      url: '/upload',
    },
    {
      icon: CopyOutlined,
      text: '模板',
      url: '/template',
    },
    {
      icon: PlayCircleOutlined,
      text: '解析',
      url: '/parse',
    },
    {
      icon: CloudDownloadOutlined,
      text: '导出',
      url: '/download',
    },
  ]);

  const route = useRoute();
  const router = useRouter();

  function go(url: string) {
    if (route.path === url) {
      return;
    }
    router.push(url);
  }

  const isActive = computed(() => (url: string) => {
    return url === route.path ? 'active side-item' : 'side-item';
  });
</script>

<style lang="less" scoped>
  .side {
    width: 60px;
    height: 100vh;
    background-color: #f9fafb;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: fixed;
    left: 0;
    top: 0;

    .side-item {
      width: 50px;
      height: 50px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      margin-top: 20px;
      color: #999;

      .side-item__text {
        font-size: 14px;
        margin-top: 4px;
      }

      &.active {
        background-color: #eff1f2;
        color: #e86ca4;
        border-radius: 6px;
      }

      &:hover {
        background-color: #eff1f2;
        border-radius: 6px;
      }
    }
  }
</style>
